var cluster = require('cluster'); // Only required if you want the worker id
var sticky = require('sticky-session');

// var server = require('http').createServer(function (req, res) {
//     res.end('worker: ' + cluster.worker.id);
// });

var express = require('express');
var app = new express();

var server = require('http').createServer(app);

if (!sticky.listen(server, 3000)) {
    // Master code
    console.log('app master.', cluster.isPrimary);

    server.once('listening', function () {
        console.log('server started on 3000 port');
    });
} else {
    // Worker code
    console.log('app worker.', cluster.isWorker, cluster.worker.id);

    require('./express')(app);
    require('./socket')(server);
}